home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / interp / stats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  5.2 KB  |  175 lines

  1.  
  2. /****** stats.c *******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:   Dec 8, 1985          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. /* Statistics collection routines */ 
  24.  
  25. #include "struct.h"
  26. #include "stats.h"
  27. #include <stdio.h>
  28.  
  29. #if STATS
  30.  
  31. long StatRecycle=0,StatFresh=0;
  32. long StatArg [MAXTAG+1];
  33. long Stat_Apply      [StatLimLen+1];
  34. long Stat_NewList    [StatLimLen+1];
  35. long Stat_DelLPtrIn  [StatLimLen+1];
  36. long Stat_DelLPtrOut [StatLimLen+1];
  37. long Stat_Construct  [StatLimLen+1];
  38. long Stat1Simple,Stat2Simple;
  39. long StatC = 0;
  40.  
  41. void StatConstant (InOut)
  42.    ObjectPtr InOut;
  43.    {
  44.       StatC++;
  45.    }
  46.  
  47. void StatConstruct (P)
  48.    ListPtr P;
  49.    {
  50.       register int N;
  51.       N = ListLength (P);
  52.       if (N >= StatLimLen) N = StatLimLen;
  53.       ++Stat_Construct[N];
  54.    }
  55.  
  56. void StatNewList (N)
  57.    long N;
  58.    {
  59.       StatFresh += N;
  60.       if (N > StatLimLen) N = StatLimLen;
  61.       ++Stat_NewList [N];
  62.    }
  63.  
  64. void StatDelLPtr (P)
  65.    register ListPtr P;
  66.    {
  67.       register int N;
  68.  
  69.       N = ListLength (P);
  70.       if (N >= StatLimLen) N = StatLimLen;
  71.  
  72.       ++Stat_DelLPtrIn [N];
  73.       for (N=0; P!=NULL; P=P->Next)
  74.      if (P->LRef > LRefOne || ++N >= StatLimLen) break; 
  75.       ++Stat_DelLPtrOut [N];
  76.    }
  77.  
  78. #define SCALAR ((1<<INT)|(1<<FLOAT)|(1<<BOOLEAN)|(1<<STRING))
  79.  
  80. void StatApply (InOut)
  81.    ObjectPtr InOut;
  82.    {
  83.       ListPtr P;
  84.       long L;
  85.  
  86.       StatArg [InOut->Tag] ++;
  87.       if (InOut->Tag == LIST) {
  88.      L = ListLength (InOut->List);
  89.      if (L > StatLimLen) L = StatLimLen;
  90.      Stat_Apply [L] ++;
  91.      if (L == 2) {
  92.         P = InOut->List;
  93.         if ((1<<P->Val.Tag) & SCALAR) Stat1Simple++;
  94.         if ((1<<P->Next->Val.Tag) & SCALAR) Stat2Simple++;
  95.      }
  96.       }
  97.    }
  98.  
  99.  
  100. /*
  101.  * ShowDist
  102.  */
  103. void ShowDist (Title,Dist)
  104.    char *Title;
  105.    long Dist[];
  106.    {
  107.       int k;
  108.       long S,Z;
  109.  
  110.       for (S=0, k=0; k<=StatLimLen; k++) S += Dist[k];
  111.  
  112.       printf ("   %s (total = %ld)\n      ",Title,S);
  113.       if (S) 
  114.      for (k=0; k<=StatLimLen; k++) {
  115.         Z = 1000 * Dist[k]/S;
  116.         printf ("%ld.%ld%% [%s%ld]   ",Z/10,Z%10,k==StatLimLen?">=":"",k);
  117.         Dist[k] = 0;
  118.      }
  119.       printf ("\n");
  120.    }
  121.  
  122. /*
  123.  * ShowStats
  124.  */
  125. void ShowStats ()
  126.    {
  127.       long Total;
  128.       int k;
  129.  
  130.       printf ("\n"); 
  131.       Total = StatRecycle + StatFresh;
  132.       printf ("Memory management\n");
  133.       printf ("   Total cells created = %ld\n",Total);
  134.       printf ("   Percent of cells recycled = %g\n",
  135.           Total ? ((double) 100*StatRecycle)/Total : 0.0);
  136.       ShowDist ("New list length distribution",Stat_NewList);
  137.       StatRecycle = StatFresh = 0;
  138.       ShowDist ("Deleted list (total) length distribution",Stat_DelLPtrIn);
  139.       ShowDist ("Deleted list (partial) length distribution",Stat_DelLPtrOut);
  140.       ShowDist ("Constructor list length distribution",Stat_Construct);
  141.       printf ("\n");
  142.  
  143.       printf ("Constant function applications = %d\n",StatC);
  144.       StatC = 0;
  145.       printf ("\n");
  146.  
  147.       if (Stat_Apply [2]) {
  148.      Stat1Simple = 100 * Stat1Simple / Stat_Apply [2];
  149.      Stat2Simple = 100 * Stat2Simple / Stat_Apply [2];
  150.       }
  151.       if (StatArg[LIST])
  152.      for (k=0; k<=StatLimLen; k++)
  153.         Stat_Apply [k] = 100 * Stat_Apply [k] / StatArg[LIST];
  154.       Total = 0;
  155.       for (k=0; k<=MAXTAG; k++) Total += StatArg [k];
  156.       if (Total)
  157.      for (k=0; k<=MAXTAG; k++) StatArg [k] = 100 * StatArg [k] / Total;
  158.       printf ("\n");
  159.       printf ("Apply arguments (Total = %ld)\n",Total);
  160.       printf ("   Boolean = %ld, Int = %ld, Float = %ld, String = %ld\n",
  161.           StatArg[BOOLEAN],StatArg[INT],StatArg[FLOAT],StatArg[STRING]);
  162.       printf ("   List = %ld\n",StatArg[LIST]);
  163.       printf ("   ");
  164.       for (k=0; k<StatLimLen; k++) printf ("%ld [%ld], ",Stat_Apply [k],k);
  165.       printf ("%ld [>=%d]\n",Stat_Apply [StatLimLen],StatLimLen);
  166.       printf ("   Pair elements [scalar]<%ld,%ld>\n",Stat1Simple,Stat2Simple);
  167.       Stat1Simple = Stat2Simple = 0;
  168.       for (k=0; k<=StatLimLen; k++) Stat_NewList [k] = Stat_Apply[k] = 0;
  169.       for (k=0; k<=MAXTAG; k++) StatArg[k] = 0;
  170.    }
  171. #endif
  172.  
  173. /**************************** end of stats.c ****************************/
  174.  
  175.